using System;
using System.Collections.Generic;
using System.ComponentModel;
using Comteck.Dto.Sys;
using Comteck.Winforms.Data;
using Comteck.Winforms.Forms;
using DevExpress.XtraBars;

namespace Comteck.Winforms.Dialog {
  /// <summary>
  /// 通用打印对话框
  /// </summary>
  public partial class FrmPrintDialog : FrmDialogBase {

    #region fields

    /// <summary>
    /// 待打印的ID集合
    /// </summary>
    [Browsable(false)]
    public List<dynamic> PrintList { get; set; }

    /// <summary>
    /// 
    /// </summary>
    [Browsable(false)]
    public string FileName { get; set; }

    /// <summary>
    /// 
    /// </summary>
    [Browsable(false)]
    public bool OpenFile { get; set; } = true;

    #endregion

    #region ctor

    public FrmPrintDialog() {
      InitializeComponent();
    }

    #endregion

    #region events

    /// <summary>
    /// 绑定数据
    /// </summary>
    /// <param name="list"></param>
    public void BindData(List<PrintTemplateDto> list) {
      this.gcMain.DataSource = list;
    }

    #endregion

    #region events

    /// <summary>
    /// 窗体加载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void FrmPrintDialog_Load(object sender, EventArgs e) {
      if (this.DesignMode) {
        return;
      }
    }

    /// <summary>
    /// 打印
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private async void btnPrint_ItemClick(object sender, ItemClickEventArgs e) {
      //  选中行的数据
      if (!(gvMain.GetFocusedRow() is PrintTemplateDto model)) {
        return;
      }

      await LocalDbDataHelper.Print(model, this.PrintList);
    }

    /// <summary>
    /// 直接导出
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btnExport_ItemClick(object sender, ItemClickEventArgs e) {
      //  选中行的数据
      if (!(gvMain.GetFocusedRow() is PrintTemplateDto model)) {
        return;
      }

      LocalDbDataHelper.Export(model, this.PrintList, null, this.OpenFile);
    }

    /// <summary>
    /// 关闭
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void BtnClose_ItemClick(object sender, ItemClickEventArgs e) {
      this.Close();
    }

    #endregion

  }
}
